
package net.atremmedia.gwt.actionjava.examples.mouse.samples;

import net.atremmedia.gwt.actionjava.examples.AJExample;
import net.atremmedia.gwt.actionjava.examples.frame.AJExampleOverview;
import actionjava.display.Graphics;
import actionjava.display.Shape;
import actionjava.events.mouse.MouseEvent;
import actionjava.events.mouse.MouseEvent.MouseEventType;
import actionjava.events.mouse.MouseOutHandler;
import actionjava.events.mouse.MouseOverHandler;

public class MouseExample7 extends AJExample
{
	public static final String NAME = "MouseExample 7";
	public static final String DESCRIPTION = "Description";
	public static final String EXAMPLE_SRC = "https://code.google.com/p/gwt-actionjava/source/browse/trunk/aj-examples/aj-examples-mouse/src/main/java/net/atremmedia/gwt/actionjava/examples/mouse/samples/MouseExample7.java";

	private Shape testFigure1;
	private Shape testFigure2;

	public MouseExample7(AJExampleOverview base)
	{
		super(NAME, DESCRIPTION, EXAMPLE_SRC, base);
	}

	@Override
	public void run()
	{
		testFigure1 = new Shape();
		moveFigure(testFigure1);
		colorFigure(testFigure1);
		addChild(testFigure1);

		testFigure1.addEventListener(MouseEventType.MOUSE_OVER, new MouseOverHandler()
		{
			@Override
			protected void mouseOverHandler(MouseEvent event)
			{
				colorFigure(testFigure1);
			}
		});

		testFigure1.addEventListener(MouseEventType.MOUSE_OUT, new MouseOutHandler()
		{

			@Override
			protected void mouseOutHandler(MouseEvent event)
			{
				moveFigure(testFigure1);
			}
		});

		testFigure2 = new Shape();
		moveFigure(testFigure2);
		colorFigure(testFigure2);
		addChild(testFigure2);

		testFigure2.addEventListener(MouseEventType.MOUSE_OVER, new MouseOverHandler()
		{
			@Override
			protected void mouseOverHandler(MouseEvent event)
			{
				colorFigure(testFigure2);
			}
		});

		testFigure2.addEventListener(MouseEventType.MOUSE_OUT, new MouseOutHandler()
		{

			@Override
			protected void mouseOutHandler(MouseEvent event)
			{
				moveFigure(testFigure2);
			}
		});

	}

	private void moveFigure(Shape figure)
	{
		figure.setX(getRandomNumber(50, 750));
		figure.setY(getRandomNumber(50, 550));
	}

	private void colorFigure(Shape figure)
	{
		Graphics graphs = figure.getGraphics();
		graphs.clear();
		graphs.beginFill(getRandomColor());
		graphs.drawCircle(-25, -25, 50);
		graphs.endFill();
	}
}
